/**
 * CollectionUtil.java
 */
package com.tobeface.sns.interfaces.util;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Dylan
 * @time 2012-7-31
 * by this class ,we can get what I have,and you have too;what I have,but you don't have;
 * what I have and what you have but I don't have;I think you know
 */
public final class CollectionUtil {

	/**
	 * ���ϸ����ϵĽ���
	 * @param one
	 * @param two
	 * @return
	 */
	public static <T> Collection<T> intersection(Collection<T> one, Collection<T> two) {
		Set<T> tempOne = new HashSet<T>(one);
		Set<T> tempTwo = new HashSet<T>(two);
		tempOne.retainAll(tempTwo);
		return tempOne;
	}
	/**
	 * �������ϵĲ���
	 * @param one
	 * @param two
	 * @return
	 */
	public static <T> Collection<T> union(Collection<T> one, Collection<? extends T> two) {
		Set<T> tempOne = new HashSet<T>(one);
		Set<T> tempTwo = new HashSet<T>(two);
		tempOne.addAll(tempTwo);
		return tempOne;
	}
	/**
	 * �������ϵĲ���
	 * @param one
	 * @param two
	 * @return
	 */
	public static <T> Collection<T> complementary(Collection<T> one, Collection<T> two) {
		Set<T> tempOne = new HashSet<T>(one);
		Set<T> tempTwo = new HashSet<T>(two);
		tempOne.removeAll(tempTwo);
		return tempOne;
	}
}
